package com.zsrt.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zsrt.Entity.UserEntity;
import com.zsrt.service.UserServiceImpl;

public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = -5251965658349799155L;
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		res.setCharacterEncoding("utf-8");
		PrintWriter out = res.getWriter();
		String userCellphone = req.getParameter("userCellphone");
		System.out.println(userCellphone);
		String checkCode = req.getParameter("checkCode");
		String password = req.getParameter("password");
		String session_checkCode = (String) req.getSession().getAttribute("code");
		if (!session_checkCode.equals(checkCode))
			out.println(0);
		else {
			UserEntity user = new UserServiceImpl().query(userCellphone);
			if (user.getUserCellphone() != null) {
				if (password.equals(user.getPassword()))
					out.println("1");
				else
					out.println("2");
			} else {
				out.println("3");
			}
			out.close();
		}
	}
}
